﻿using AnesSystem.Models;
using AnesSystem.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels
{
    public class MaZuiTongJiCtrlViewModel : BaseCountCtrlViewModel<MaZuiTongJiCtrlViewModel>
    {
        #region Variables
        #endregion

        #region Constructor
        public MaZuiTongJiCtrlViewModel()
        { }


        #endregion

        #region Properties




        #endregion

        #region 依赖属性

        #endregion

        #region Event

        #endregion

        #region Private Methods
        #endregion

        #region Public/Protected Methods
  

        public void UpdateDisPatientLinkModelList(BaseCountModel SelBaseCountModel)
        {
            if (SelBaseCountModel == null) return;
            DisPatientLinkModelList.Clear();
            if ("空".Equals(SelBaseCountModel.Name))
                DisPatientLinkModelList = PatientLinkModelList.Where(O =>
                {
                    if (string.IsNullOrEmpty(O.AnesthesiaRecord.Mzff))
                        return true;
                    return false;

                }).ToList();
            else if (SelBaseCountModel.Name != null)
            {
                DisPatientLinkModelList = PatientLinkModelList.Where(O =>
                {
                    if (!string.IsNullOrEmpty(O.AnesthesiaRecord.Mzff))
                        return O.AnesthesiaRecord.Mzff.Equals(SelBaseCountModel.Name);
                    return false;

                }).ToList();
            }
        }

        public override void UpdateBaseCountModelList()
        {
            foreach (PatientLinkModel patientLinkModel in PatientLinkModelList)
            {

                bool onOff = true;
                //Mzff麻醉方式
                //获取手术医生姓名
                if (patientLinkModel.AnesthesiaRecord.Mzff != null)
                {
                    string name = patientLinkModel.AnesthesiaRecord.Mzff;
                    if (string.IsNullOrEmpty(name)) name = "空";
                    foreach (BaseCountModel baseCountModel in BaseCountModelList)
                    {
                        if (baseCountModel.Name.Equals(name))
                        {
                            onOff = false;
                            baseCountModel.Count++;
                        }
                    }
                    if (onOff && !string.IsNullOrEmpty(name))
                    {
                        BaseCountModel baseCountModel = new BaseCountModel();
                        baseCountModel.Name = name;
                        baseCountModel.Count = 1;
                        BaseCountModelList.Add(baseCountModel);
                    }
                }
            }
        }

        public void Excel()
        {
            
            if (PatientLinkModelList == null || PatientLinkModelList.Count == 0)
            {
                MessageBoxCommon.ShowDialog("请先查询病人!", MessageBoxCommon.OK);
                return;
            }
            if (DisPatientLinkModelList == null || DisPatientLinkModelList.Count == 0)
            {
                MessageBoxCommon.ShowDialog("请先选择病人集合!", MessageBoxCommon.OK);
                return;
            }
            ExportToExcel excel = new ExportToExcel();
            excel.ExportParameterCommon("历史手术", DisPatientLinkModelList.ToList());
        }

        #endregion

        #region EventHandlers

        #endregion
    }
}
